package com.letfox.common.exception;

import com.letfox.common.util.http.HTTPStatusEnum;



/**
 * 管理端异常自定义
 * 
 */
public class HTTPException extends RuntimeException {

    private static final long serialVersionUID = 3380527655305563701L;

    private String code;
    private String message;
    private String desc;
    private HTTPStatusEnum HTTPStatusEnum;

    public HTTPException(HTTPStatusEnum HTTPStatusEnum, Throwable cause) {
        super("[" + HTTPStatusEnum.getCode() + "]" + HTTPStatusEnum.getDesc(), cause);
        this.HTTPStatusEnum = HTTPStatusEnum;
        this.code = HTTPStatusEnum.getCode();
        this.message = HTTPStatusEnum.getDesc();
        if (cause != null) {
            if (cause instanceof HTTPException) {
                HTTPException managerException = (HTTPException) cause;
                this.code = managerException.getCode();
                this.message = managerException.getMessage();
            }
        }
    }
    
    public HTTPException(HTTPStatusEnum HTTPStatusEnum, String keys, Throwable cause) {
        super("[" + HTTPStatusEnum.getCode() + "]" + HTTPStatusEnum.getDesc(), cause);
        this.HTTPStatusEnum = HTTPStatusEnum;
        this.code = HTTPStatusEnum.getCode();
        this.message = "[" + keys + "]" + HTTPStatusEnum.getDesc();
        if (cause != null) {
            if (cause instanceof HTTPException) {
                HTTPException managerException = (HTTPException) cause;
                this.code = managerException.getCode();
                this.message = managerException.getMessage();
            }
        }
    }
    
    public HTTPException(HTTPStatusEnum HTTPStatusEnum, String keys, String desc, Throwable cause) {
        super("[" + HTTPStatusEnum.getCode() + "]" + HTTPStatusEnum.getDesc(), cause);
        this.HTTPStatusEnum = HTTPStatusEnum;
        this.code = HTTPStatusEnum.getCode();
        this.message = "[" + HTTPStatusEnum.getCode() + "]" + HTTPStatusEnum.getDesc();
        this.desc = desc;
        if (cause != null) {
            if (cause instanceof HTTPException) {
                HTTPException managerException = (HTTPException) cause;
                this.code = managerException.getCode();
                this.message = managerException.getMessage();
            }
        }
    }
    
    public HTTPException(String keys, String desc, Throwable cause) {
        super("[" + keys + "]" + desc, cause);
        this.HTTPStatusEnum = HTTPStatusEnum.valueOf(keys);
        this.code = keys;
        this.message = "[" + keys + "]" + desc;
        if (cause != null) {
            if (cause instanceof HTTPException) {
                HTTPException managerException = (HTTPException) cause;
                this.code = managerException.getCode();
                this.message = managerException.getMessage();
            }
        }
    }
    
    public HTTPException(HTTPStatusEnum HTTPStatusEnum, String desc) {
        super("[" + HTTPStatusEnum.getCode() + "]" + HTTPStatusEnum.getDesc() + desc);
        this.HTTPStatusEnum = HTTPStatusEnum;
        this.code = HTTPStatusEnum.getCode();
        this.message = "[" + HTTPStatusEnum.getCode() + "]" + HTTPStatusEnum.getDesc();
    }
    
    public HTTPException(HTTPStatusEnum HTTPStatusEnum) {
        this(HTTPStatusEnum, "");
    }
    
    public HTTPException(String desc) {
        this("", desc, null);
    }
    
    

    public HTTPStatusEnum getErrorEnum() {
        return HTTPStatusEnum;
    }

    public void setErrorEnum(HTTPStatusEnum HTTPStatusEnum) {
        this.HTTPStatusEnum = HTTPStatusEnum;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    @Override
    public String toString() {
        return "[" + code + "]" + message;
    }
}
